import java.util.Arrays;

class MyThread extends Thread{
    @Override
    public void run() {
        synchronized (new String()){

        }
        while (true)
        System.out.println("Thread");
    }
}
public class Demo1 {
    public static void main(String[] args) {
        Thread t = new MyThread();
        t.start();
        while(true) System.out.println("main");
    }
}
class Solution {
    public int largestSumAfterKNegations(int[] nums, int k) {
        Arrays.sort(nums);
        int sum = 0;
        for(int i=0; i<nums.length; i++){
            if(nums[i]>0){
                sum += nums[i];
            }else if(nums[i]<0){
                if(k>0){
                    k--;
                    nums[i] = -nums[i];
                }
                sum += nums[i];
            }
        }
        Arrays.sort(nums);
        if(k%2 == 0) return sum;
        else return sum-2*nums[0];
    }
}
class Solution1 {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        int sum = 0, total = 0, begin = 0;
        for(int i=0; i<gas.length; i++){
            sum += (gas[i]-cost[i]);
            total += (gas[i]-cost[i]);
            if(sum < 0){
                sum = 0;
                begin = i+1;
            }
        }
        if(total < 0) return -1;
        return begin;
    }
}